/* eslint-disable import/prefer-default-export */
/* eslint-disable max-classes-per-file */

import { JsonProperty, Serializable } from '@/plugins/reflect-metadata';

@Serializable()
export class AuthContentRole {
  @JsonProperty('name')
    name: string = '';

  @JsonProperty('users')
    users: string[] = [];

  @JsonProperty('permissions')
    permissions: string[] = [];
}

@Serializable()
class AuthContent {
  @JsonProperty('appid')
    appid: string = '';

  @JsonProperty({ name: 'roles', type: AuthContentRole })
    roles: AuthContentRole[] = [];

  @JsonProperty('permissions')
    permissions: string[] = [];
}

@Serializable()
export class AuthMeta {
  @JsonProperty('id')
    id: number = 0;

  @JsonProperty('data_id')
    dataId: string = '';

  @JsonProperty('content_type')
    contentType: string = '';

  @JsonProperty('kind')
    kind: string = '';

  @JsonProperty('time')
    time: string = '';

  @JsonProperty('desc')
    desc: string = '';

  @JsonProperty('remark')
    remark: string = '';

  @JsonProperty('operator')
    operator: string = '';
}

@Serializable()
export class AuthItem {
  @JsonProperty('content')
    content: AuthContent = new AuthContent();

  @JsonProperty('meta')
    meta: AuthMeta = new AuthMeta();

  get params() {
    return {
      content: JSON.stringify(this.content, null, 2),
      remark: this.meta.remark,
      mtime: this.meta.time,
    };
  }
}
